#include <iostream>
using namespace std;

class Point{
private:
    int _x;
    int _y;

public:
    //普通构造函数
Point(int x,int y):
    _x(x)
    ,_y(y){
        cout<<"normal function"<<endl;
    }
    //拷贝构造函数
Point(const Point & ref):
    _x(ref._x)
    ,_y(ref._y){
        cout<<"copy function"<<endl;
    }
    //析构函数
        ~Point(){
            cout<<"delete function"<<endl;
        }
        void display(){
            cout<<"x="<<_x<<","<<"y="<<_y<<endl;
        }
};
//按值传递的方法调用对象，会调用拷贝构造函数传参一个副本对象
void processPoint(Point pt){
    cout<<"in processPoint"<<endl;
    pt.display();
}
Point create_Point(int x,int y){
    Point temp(x,y);
    return temp;
}
    
int main(int argc, char * argv[]){
    cout<<"=====创建原始对象======"<<endl;
    Point original(10,20);
    cout<<&original<<endl;
    cout<<"=====直接初始化拷贝======"<<endl;
    Point copy1=original;
    cout<<&copy1<<endl;
    cout<<"====使用括号初始化======"<<endl;
    Point copy2(original);
    cout<<&copy2<<endl;
    cout<<"======函数参数传递======="<<endl;
    processPoint(original);
    cout<<"=====创建副本获取返回值==="<<endl;
    Point copy3=create_Point(10,20);
    cout<<&copy3<<endl;
    cout<<"====main函数即将结束====="<<endl;

    return 0;
}

